from django.db import models

from cate.models import Cate
from my.models import User


# Create your models here.
class Article(models.Model):
    title = models.CharField(
        max_length=120,
        verbose_name="文章标题",
        default="未命名",
    )
    content = models.TextField(
        max_length=2000,
        verbose_name="文章内容",
        default="",
        blank=True,
    )

    cover_img = models.CharField(
        max_length=1024,
        verbose_name="文章封面地址",
        default="",
    )

    pub_date = models.DateField(
        verbose_name="文章发布时间",
        auto_now_add=True,
    )

    state_choice = [
        (0, "已发布"),
        (1, "草稿"),
    ]
    state = models.PositiveSmallIntegerField(
        choices=state_choice,
        verbose_name="文章状态",
        default=1
    )
    cate_id = models.ForeignKey(
        Cate,
        to_field='id',
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name="articles",
        verbose_name="文章所属分类",
    )

    user_id = models.ForeignKey(
        User,
        to_field='id',
        on_delete=models.CASCADE,
        related_name="articles",
        verbose_name="文章作者id"
    )